package dao

import (
	"goWeb/bookStore/model"
	"goWeb/bookStore/utils"
)

func ValidateUser(username string, password string) (user *model.User, err error) {
	sqlstr := "select Id,Username,Password,Email from bs_user where Username=? and Password=?"
	row := utils.Db.QueryRow(sqlstr, username, password)
	user = &model.User{}
	row.Scan(&user.Id, &user.Username, &user.Password, &user.Email)
	return user, nil
}

func GetUserByName(username string) (user *model.User, err error) {
	sqlstr := "select Id,Username,Password,Email from bs_user where Username=?"
	row := utils.Db.QueryRow(sqlstr, username)
	user = &model.User{}
	row.Scan(&user.Id, &user.Username, &user.Password, &user.Email)
	return user, nil
}

func RegisterUser(username string, password string, email string) {
	sqlstr := "insert into bs_user (username,Password,Email) values(?,?,?)"
	utils.Db.Exec(sqlstr, username, password, email)
}
